home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------------------------
- // Event Handling Code
- //
- // by Philip McBride
- // code taken freely from Apple DTS sample code
- //
- //--------------------------------------------------------------------------------------------
-
-
- #include <AppleEvents.h>
- #include <Drag.h>
- #include <GestaltEqu.h>
- #include <Memory.h>
- #include <SegLoad.h>
- #include <StandardFile.h>
-
- #include "GameControls.h"
- #include "AEVT.h"
- #include "extern.h"
- #include "file.h"
- #include "document.h"
- #include "event.h"
-
-
- //--------------------------------------------------------------------------------------------
- // Handle High Level Event
- //
- void DoHighLevelEvent(EventRecord *ev)
- {
- OSErr err;
-
- err = AEProcessAppleEvent(ev);
- }
-
-
- //--------------------------------------------------------------------------------------------
- // Handle Open Application
- //
- pascal OSErr MyAEHandleOAPP(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
- {
- OSErr err = noErr ;
- SFTypeList theTypeList = {'3DMF'};
- StandardFileReply theReply;
-
- *theAppleEvent = *theAppleEvent;
- *reply = *reply;
- refCon = refCon;
-
- StandardGetFile(0L, 1, theTypeList, &theReply);
-
- // if we had a good file reply, then handle the file opening.
- if (theReply.sfGood)
- HandleOpenDoc(&theReply.sfFile);
-
- return err;
- }
-
-
- //-----------------------------------------------------------------------
- // Handle Open Document
- //
- pascal OSErr MyAEHandleODOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
- {
- FSSpec myFSS;
- AEDescList docList;
- OSErr err,
- ignoreErr;
- long index,
- itemsInList;
- Size actualSize;
- AEKeyword keywd;
- DescType returnedType;
-
- *theAppleEvent = *theAppleEvent;
- *reply = *reply;
- refCon = refCon;
-
- err = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&docList);
- if (err == noErr) {
-
- // see how many descriptor items are in the list
- // this is the number of documents we want to open
- err = AECountItems(&docList,&itemsInList);
-
- // now get each descriptor record from the list
- // coerce the returned data to an FSSpec record, and
- // open the asoociated file
-
- for (index=1; index <= itemsInList && err == noErr; index++) {
-
- err = AEGetNthPtr( &docList,
- index,
- typeFSS,
- &keywd,
- &returnedType,
- (Ptr)&myFSS,
- sizeof(myFSS),
- &actualSize);
-
- if (err == noErr) {
-
- FInfo fndrInfo ;
-
- // we now have a valid FSSpec to reference the file, we need to know
- // what type the file is to determine which file open function to call
- // we can determine this from the finder info for the file
-
- err = FSpGetFInfo( &myFSS, &fndrInfo );
-
- // if we got that ok, then we switch on the file
- // type (we don't care about the creator type)
-
- if (err == noErr) {
-
- switch( fndrInfo.fdType ) {
- case 'TEXT':
- case '3DMF':
- HandleOpenDoc(&myFSS);
- break ;
- default:
- MySendQuitApp();
- break ;
- }
- }
- }
- }
- ignoreErr = AEDisposeDesc(&docList);
- }
- return err ;
- }
-
- //-----------------------------------------------------------------------
- // Handle Print Document
- //
- pascal OSErr MyAEHandlePDOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
- {
- // not using these variables
- theAppleEvent = theAppleEvent;
- reply = reply;
- refCon = refCon;
-
- return noErr;
- }
-
- //--------------------------------------------------------------------------------------------
- // Handle Quit
- //
- pascal OSErr MyAEHandleQUIT(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
- {
- OSErr err = noErr ; // used as return value
- WindowPtr theWindow;
-
- // not using these variables
- theAppleEvent = theAppleEvent;
- reply = reply;
- refCon = refCon;
-
- gQuitting = true;
-
- // attempt to close the document if window left open
- theWindow = (WindowPtr)FrontWindow();
- if (theWindow)
- MyCloseDocument((DocumentPtr ) (((WindowPeek) theWindow)->refCon));
-
- // if we closed everything up successfully, we can return noErr, otherwise
- // indicate to sender of the 'quit' aevt that we canceled
-
- if (gQuitting) {
- gQuit = true; // user didn't cancel
- err = AEDisposeDesc(&pSelfAddress); // Dispose of my self-addressed descriptor.
- }
- else {
- err = userCanceledErr ;
- }
-
- return err ;
- }
-
- //--------------------------------------------------------------------------------------------
- // Send a Quit Message
- //
- void MySendQuitApp( void )
- {
- AppleEvent myAppleEvent, reply;
- OSErr err;
-
- // Create the Apple Event.
- err = AECreateAppleEvent( kCoreEventClass,
- kAEQuitApplication,
- &pSelfAddress,
- kAutoGenerateReturnID,
- kAnyTransactionID,
- &myAppleEvent);
-
- // Send the Apple Event.
- err = AESend( &myAppleEvent,
- &reply,
- kAENoReply+kAENeverInteract,
- kAENormalPriority,
- kAEDefaultTimeout,
- nil,
- nil);
-
- AEDisposeDesc(&myAppleEvent); // Dispose of the Apple Event.
- }
-
- //--------------------------------------------------------------------------------------------
- // Send an Open Document Message
- //
- void MySendOpenDoc(FSSpec *myFSSpec)
- {
- myFSSpec = myFSSpec;
- }
-
- //--------------------------------------------------------------------------------------------
- // Send a Print Message
- //
- void MySendPrintDoc(FSSpec *myFSSpec)
- {
- myFSSpec = myFSSpec;
- }
-
-
-